Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vendor the 0.54.1 prometheus dependency to avoid conflict with Agent/EDOT #42890

Closed

Conversation

tommyers-elastic
Copy link
Contributor

@tommyers-elastic tommyers-elastic commented Feb 25, 2025

The context here, in short, is - Elastic Agent includes OTel Collector, which has a dependency on prometheus v3.x. Elastic Agent also includes Beats (as a go dependency, not just in the bundle), which has a dependency on prometheus v2.x. Due to some potentially breaking changes in the upgrade between prometheus 2 and 3, we need to vendor the prometheus 2 dependency into Beats for a short period of time.

The changes here are generated from the script in the commit message. It's not ideal, but it's the only way I could find to make a 'go mod vendor'-esque output for a single module.

This is a short term situation whilst we spend the time properly validating the prometheus 2->3 changes.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Disruptive User Impact

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Use cases

Screenshots

Logs

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Feb 25, 2025
Copy link
Contributor

mergify bot commented Feb 25, 2025

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @tommyers-elastic? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

@ishleenk17
Copy link
Contributor

We also have Prometheus metricbeat code in x-pack

x-pack/metricbeat/module/prometheus

That would need library changes as well.

@tommyers-elastic
Copy link
Contributor Author

@ishleenk17 there's no usages of the github.com/prometheus/prometheus lib there. if there were any remaining imports they would fail anyway.

either way it doesn't matter, this PR is no longer required. the beats dependency in agent is being removed, which solves the problem of the mismatched otel dep.

@cmacknz cmacknz reopened this Feb 27, 2025
@cmacknz cmacknz added backport-8.x Automated backport to the 8.x branch with mergify backport-8.18 Automated backport to the 8.18 branch backport-9.0 Automated backport to the 9.0 branch labels Feb 27, 2025
@cmacknz
Copy link
Member

cmacknz commented Feb 27, 2025

Re-opened, we are going to need this to restore Beats receivers in the 9.0 branch and allow us to keep them in 8.18.

… with Otel collector deps in elastic agent.

[git-generate]
# this is pretty nasty, but it's the best way i could find to reliably get only the required source
#
# the way the whole thing works in general is: in go.mod, you replace the module you want to vendor
# with a different name, using the major version suffix notation. you then add a 'replace' statement
# which points to a local copy of that module at a specific version.
#
# this script will not work if the module you are trying to vendor is already vendored. before running
# it, the module you wish to vendor should currently be used as-is in the beats source. if you need to
# update an already vendored module, you should first 'un-vendor' it, then run this script fresh.
#
# when you're ready, run this script from the root go module directory.

module=github.com/prometheus/prometheus
version=v0.54.1
go_import_path=${module}@${version}
go_mod_path=https://raw.githubusercontent.com/prometheus/prometheus/refs/tags/${version}/go.mod

# ensure the correct version is in the root go.mod file so the right sources are downloaded in the next step
go get ${go_import_path}

# there's no way to selectively vendor, so we have to get everything ...
go mod vendor

# copy our module to a non-go-managed vendor directory and add a go.mod
mkdir -p _vendor/${go_import_path}
cp -R vendor/${module}/ _vendor/${go_import_path}
curl ${go_mod_path} -o _vendor/${go_import_path}/go.mod

pushd _vendor/${go_import_path}

# this removes unnecessary dependencies from the vendored source
go mod tidy

popd

rm -r vendor

# update go.mod with the vendored module
go mod edit -droprequire=${module}
go mod edit -require=${module}/v2@v2.54.1
go mod edit -replace=${module}/v2=./_vendor/${go_import_path}

# replace the existing imports
grep -Rl --include="*.go" ${module} | xargs sed -i "" "s|${module}|${module}/v2|g"

go mod tidy
@tommyers-elastic tommyers-elastic force-pushed the vendor-prometheus2-dep branch from fac1123 to f4a1d30 Compare March 4, 2025 11:06
@tommyers-elastic tommyers-elastic marked this pull request as ready for review March 4, 2025 11:16
@tommyers-elastic tommyers-elastic requested review from a team as code owners March 4, 2025 11:16
@pierrehilbert pierrehilbert added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label Mar 4, 2025
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Mar 4, 2025
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@pierrehilbert pierrehilbert added the Team:obs-ds-hosted-services Label for the Observability Hosted Services team label Mar 4, 2025
@pierrehilbert pierrehilbert added needs_team Indicates that the issue/PR needs a Team:* label Team:Obs-InfraObs Label for the Observability Infrastructure Monitoring team labels Mar 4, 2025
@elasticmachine
Copy link
Collaborator

Pinging @elastic/obs-ds-hosted-services (Team:obs-ds-hosted-services)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Mar 4, 2025
@botelastic
Copy link

botelastic bot commented Mar 4, 2025

This pull request doesn't have a Team:<team> label.

@ishleenk17
Copy link
Contributor

/test

@shmsr
Copy link
Member

shmsr commented Mar 5, 2025

@tommyers-elastic This could lead to issues for repos that depends on beats.

#39840 (see the PR's description)

See: golang/go#30354 (comment)
See: golang/go#30354 (comment)

So, what most probably will happen here is that those repos will start breaking because go will try to look for github.com/prometheus/prometheus/v2 as per go.mod and it won't respect the replace directives beats' go.mod

@tommyers-elastic
Copy link
Contributor Author

closing due to issues this would cause with upstream beats dependencies golang/go#30354 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-8.x Automated backport to the 8.x branch with mergify backport-8.18 Automated backport to the 8.18 branch backport-9.0 Automated backport to the 9.0 branch Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team Team:obs-ds-hosted-services Label for the Observability Hosted Services team Team:Obs-InfraObs Label for the Observability Infrastructure Monitoring team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants